package com.judian.smart.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.judian.smart.activity.MainActivity;


/**
 * 开机启动SBKService服务
 *
 * @auther yyx
 */
public class SBKReceiver extends BroadcastReceiver {

    int index = 0;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED") || intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY) ) {
            // yyx: 如果启动过一次后就不再启动了
            index = 1;
            //yyx开机启动mainActivity
            Intent playIntent = new Intent(context, MainActivity.class);
            playIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(playIntent);
            //yyx启动后立即模拟home键 这样可以解决后台时屏幕闪动的问题
//            Intent i = new Intent(Intent.ACTION_MAIN);
//            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            i.addCategory(Intent.CATEGORY_HOME);
//            MyApplication.getInstance().startActivity(i);

        }
    }
}
